package org.example.service;

import org.example.dao.UserLoginDao;
import org.example.model.User;
import org.example.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserLoginService {
    @Autowired
    UserLoginDao userLoginDao;
    public User login(String account, String password) {
        User user = userLoginDao.login(account, password);
        if (user!=null){
            String userToken = JWTUtil.getToken(user);
            user.setUserToken(userToken);
            System.out.println("userToken: "+userToken);
        }
        return user;

    }

    public void register(User user) {
        userLoginDao.register(user);
    }

    public User checkAccount(String account) {
        return userLoginDao.checkAccount(account);
    }
}
